<template>
  <div>
    <p>
      click {{ $store.state.count }} times, count is
      {{ $store.getters.oddOrEven }}
    </p>
    <button @click="increment">+</button>
    <button @click="decrement">-</button>
    <button @click="incrementIfOdd">increment if odd</button>
    <button @click="incrementAsync">increment async</button>
  </div>
</template>

<script>
export default {
  name: "App",
  // mounted() {
  //   console.log(this);
  // },
  methods: {
    increment() {
      // 触发action函数
      // 传递参数只能有一个
      this.$store.dispatch("increment", 1);
    },
    decrement() {
      // 触发action函数
      this.$store.dispatch("decrement", 1);
    },
    incrementIfOdd() {
      this.$store.dispatch("incrementIfOdd", 1);
    },
    incrementAsync() {
      this.$store.dispatch("incrementAsync", 1);
    },
  },
};
</script>

<style>
</style>